package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.Setmeal;
import com.itheima.domain.ShoppingCart;
import com.itheima.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public R add(@RequestBody ShoppingCart shoppingCart){
        ShoppingCart cart = shoppingCartService.add(shoppingCart);
        return R.success(cart);

    }

    @GetMapping("/list")
    public R list(){
        List<ShoppingCart> list = shoppingCartService.listAll();
        return R.success(list);
    }

    @DeleteMapping("/clean")
    public R deleteAll(){
        shoppingCartService.deleteAll();
        return R.success("删除成功");
    }
    @PostMapping("/sub")
    public R updateGou(@RequestBody ShoppingCart shoppingCart){
        ShoppingCart sc = shoppingCartService.updateGou(shoppingCart);
        return R.success(sc);
    }
 }   